package semiProject_army.mvc.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import semiProject_army.mvc.beans.*;

public class ViewAction implements ActionHandler {

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws IOException, ServletException {
		String no = req.getParameter("no");
		String pageNum = req.getParameter("pageNum");
		String tbname = req.getParameter("tbname");
		
		String title="자유게시판";
		if(req.getParameter("tbname").equals("faq")) title="FAQ";
		else if(req.getParameter("tbname").equals("notice")) title="공지사항";
		else if(req.getParameter("tbname").equals("edu")) title="교육마당";
		else if(req.getParameter("tbname").equals("cul")) title="문화마당";
		
		if(no == null || pageNum == null || no.equals("0") || pageNum.equals("0")) {
			res.setContentType("text/html; charset=utf-8");
			PrintWriter out = res.getWriter();
			out.println("<script type='text/javascript'>");
			out.println("	alert('정상적인 접근이 아닙니다.');");
			out.println("	window.history.back();");
			out.println("</script>");
			return null;		
		} 
		
		/*BoardDAO dao = BoardDAO.getInstance();				
		BoardBean board = dao.getBoard(tbname, Integer.valueOf(no), true);
		
		String content = board.getContent();
		content = content.replaceAll("\r\n", "<br/>");
		content = content.replaceAll(" ", "&nbsp;");
		
		board.setContent(content);

		req.setAttribute("pageNum", Integer.valueOf(pageNum));
		req.setAttribute("board", board);
				*/
		req.setAttribute("action", "board/view");
		req.setAttribute("boardtitle", title);

		return viewPage;
	}
	
}
